﻿using System;
using NUnit.Framework;
using StartReading.Security.Validation;

namespace StartReading.Tests.Security.Tests.Validation
{
    [TestFixture]
    class EmailValidationTests
    {        
        private string Email { get; set; }
        private TestDelegate IsValid { get; set; }

        private void IsEmailValid()
        {
            EmailValidation.Instance.IsValid(this.Email);
        }

        [SetUp]
        public void BeforeEachTest()
        {            
            this.IsValid = this.IsEmailValid;
        }

        [TearDown]
        public void AfterEachTest()
        {            
            this.IsValid = null;
            this.Email = null;
        }
        
        [Test]
        public void Validate_UpperCaseOutlookEmail_NoException()
        {
            this.Email = "123.ABC_def@OUTLOOK.COM";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_OutlookEmail_NoException()
        {
            this.Email = "123.ABC_def@outlook.com";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_HotmailEmail_NoException()
        {
            this.Email = "123.ABC_def@hotmail.com";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_LiveEmail_NoException()
        {
            this.Email = "123.ABC_def@live.com";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_YahooEmail_NoException()
        {
            this.Email = "123.ABC_def@yahoo.com";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_UkYahooEmail_NoException()
        {
            this.Email = "123.ABC_def@yahoo.co.uk";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_AustralianYahooEmail_NoException()
        {
            this.Email = "123.ABC_def@yahoo.com.au";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_GMailEmail_NoException()
        {
            this.Email = "123.ABC_def@gmail.com";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_AolEmail_NoException()
        {
            this.Email = "123.ABC_def@aol.com";
            Assert.DoesNotThrow( this.IsEmailValid );
        }

        [Test]
        public void Validate_SpamComEmail_ReturnsException()
        {
            this.Email = "123.ABC_def@spam.com";
            Assert.Throws(typeof( ArgumentException ), this.IsEmailValid );
        }

        [Test]
        public void Validate_SpamCoEmail_ReturnsException()
        {
            this.Email = "123.ABC_def@spam.co.co";
            Assert.Throws( typeof( ArgumentException ), this.IsEmailValid );
        }

        [Test]
        public void Validate_OnlyOutlookDomainEmail_ReturnsException()
        {
            this.Email = "@outlook.com";
            Assert.Throws( typeof( ArgumentException ), this.IsEmailValid );
        }

        [Test]
        public void Validate_EmptyEmail_ReturnsException()
        {
            this.Email = String.Empty;
            Assert.Throws( typeof( ArgumentException ), this.IsEmailValid );
        }

        [Test]
        public void Validate_NullEmail_ReturnsException()
        {
            this.Email = null;
            Assert.Throws( typeof( ArgumentException ), this.IsEmailValid );
        }

        [Test]
        public void Validate_WithoutDomainEmail_ReturnsException()
        {
            this.Email = "123.ABC_def";
            Assert.Throws( typeof( ArgumentException ), this.IsEmailValid );
        }
    }
}
